# -*- coding: utf-8 -*-
import pygame
import event
import logging
from common import *

class EventLooper:
    def __init__(self, event_producer, dispatcher, frame_rate = 60):
        self.event_producer = event_producer
        self.dispatcher = dispatcher
        self.frame_rate = frame_rate
        self.clock = CLOCK
        self.stop = False
        
    def start(self):
#        pygame_event_translator = event.PygameEventTranslator()
        while not self.stop:
#            for e in pygame.event.get():
#                new_event = pygame_event_translator.translate(e)
#                if new_event == None: #不感兴趣的event
##                    warn_msg = 'Translate pygame event %d error!' % e.type
##                    logging.warning(warn_msg)
#                    continue
#                self.dispatcher.dispatch(new_event)
            for new_event in self.event_producer:
                self.dispatcher.dispatch(new_event)
            self.clock.tick(self.frame_rate)
            
    def stop(self):
        self.stop = True